package com.aiapphub.BaseCode.utils;

public class TimeUtils {
    
    // 每分钟的秒数常量
    public static final int SECONDS_PER_MINUTE = 60; 
    // 每小时的分钟数常量
    public static final int MINUTES_PER_HOUR = 60; 
    public static final int HOURS_PER_DAY = 24; // 每天的小时数常量
    
    /**
     * 将秒数转换为时分秒格式的字符串
     * @param seconds 秒数
     * @return 时分秒格式的字符串，如 "02:30:05"
     */
    public static String formatSeconds(int seconds) {
        int hours = seconds / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR); // 计算小时数
        int minutes = (seconds % (SECONDS_PER_MINUTE * MINUTES_PER_HOUR)) / SECONDS_PER_MINUTE; // 计算分钟数
        seconds = seconds % SECONDS_PER_MINUTE; // 计算剩余秒数
        return String.format("%02d:%02d:%02d", hours, minutes, seconds); // 格式化输出
    }
    
    /**
     * 将秒数转换为天时分秒格式的字符串
     * @param seconds 秒数
     * @return 天时分秒格式的字符串，如 "1天02:30:05"
     */
    public static String formatSecondsWithDays(int seconds) {
        int days = seconds / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY); // 计算天数
        seconds = seconds % (SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY); // 计算剩余秒数
        return String.format("%d天%s", days, formatSeconds(seconds)); // 格式化输出
    }
}